<script setup lang="ts">
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import router from "@/router";
import { useDetail } from "@/views/complain/utils/hooks";
import { reactive, ref } from "vue";
import { getComplainList, getResidentialList } from "@/api/property";
import { hasAuth } from "@/router/utils";

defineOptions({
  name: "complainList"
});

const form = reactive({
  name: ""
});
const loading = ref(true);
const resetForm = () => {
  form.name.value = "";
};
const residentialList = ref([]);
const residential = ref();
const dataList = ref([]);
const { toDetail } = useDetail();
const complainDialog = ref(true);
const complianInfo = ref();

//初始化数据
async function onSearch() {
  //获取小区列表
  getResidentialList().then(res => {
    residentialList.value = res.data.records;
  });
  console.log(hasAuth('1'))
  loading.value = false;
}

const getComplain = () => {
  getComplainList({ name: form.name, residentialId: residential.value }).then(res => {
    dataList.value = res.data;
  });
};
onSearch();
</script>

<template>
  <div class="main">
    <el-form
      ref="formRef"
      :inline="true"
      :model="form"
      class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
    >
      <el-form-item label="投诉内容：" prop="name">
        <el-input
          v-model="form.name"
          placeholder="请输入投诉内容"
          clearable
          class="!w-[180px]"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :icon="useRenderIcon(Search)"
          :loading="loading"
          @click="getComplain"
        >
          搜索
        </el-button>
        <el-button :icon="useRenderIcon(Refresh)" @click="resetForm()">
          重置
        </el-button>
      </el-form-item>
      <br />
      <el-form-item label="归属小区">
        <el-radio-group
          v-model="residential"
          size="small"
          @change="getComplain"
        >

          <el-radio-button label="-1" v-if="hasAuth('1')">
            社区
          </el-radio-button>
          <el-radio-button
            v-for="list in residentialList"
            :label="list.id"
            :value="list.id"
          >{{ list.name }}
          </el-radio-button
          >
        </el-radio-group>
      </el-form-item>
    </el-form>
    <el-table :data="dataList.records" table-layout="fixed">
      <el-table-column prop="id" label="ID" />
      <el-table-column label="投诉人">
        <template #default="scope">
          <el-tag v-if="scope.row.isAnonymous===true">匿名</el-tag>
          <el-tag v-if="scope.row.isAnonymous===false">{{ scope.row.userId }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="reply" label="回复内容" />
      <el-table-column prop="created" label="投诉时间" />
      <el-table-column prop="operatorId" label="处理人员" />
      <el-table-column prop="updated" label="处理时间" />
      <el-table-column prop="score" label="评分" />
      <el-table-column label="操作">
        <template v-slot="scope">
          <el-button
            type="primary"
            size="small"
            v-if="scope.row.operatorId===null"
            @click="toDetail({id:scope.row.id},'params')"
          >处理
          </el-button>
          <el-button
            type="danger"
            size="small"
            @click="complainDialog=true;complianInfo.id.value = scope.row.id"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="width: 100%">
      <el-pagination
        style="float: right"
        background
        layout="prev, pager, next"
        :total="dataList.total"
        :page-count="dataList.current"
      />
    </div>
  </div>

</template>

<style scoped lang="scss">

</style>
